package com.kkd.kkdapp.activity;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.utils.LogUtil;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.Animator.AnimatorListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

/**
 * 提前还款
 * 
 * @author mty
 * 
 */
public class PrepaymentActivity extends BaseActivity implements OnClickListener {

	private RelativeLayout dealdetails_rl; // 明细
	private LinearLayout deadline_ll;
	private int switchNo = 1;
	private RelativeLayout add_title_img; // 后退
	private int deadline_ll_height;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_prepayment);
		initView();
		setListener();
	}

	public void initView() {
		dealdetails_rl = (RelativeLayout) this
				.findViewById(R.id.dealdetails_rl);
		deadline_ll = (LinearLayout) this.findViewById(R.id.deadline_ll);
		add_title_img = (RelativeLayout) this.findViewById(R.id.add_title_img);
	}

	public void setListener() {
		dealdetails_rl.setOnClickListener(this);
		add_title_img.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.add_title_img:
			finish();
			break;
		case R.id.dealdetails_rl:
			if (switchNo % 2 != 0) {
				animTranslate(deadline_ll);
			} else {
				againstanimTranslate(deadline_ll);
			}
			switchNo++;
			break;
		}
	}

	public void animTranslate(final View view) {
		deadline_ll_height = deadline_ll.getHeight();
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", 0, -deadline_ll_height);
		animation = ObjectAnimator.ofPropertyValuesHolder(view, pvhY);
		animation.setDuration(300);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animator animation) {
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		animation.start();
	}

	public void againstanimTranslate(final View view) {
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", -deadline_ll_height, 0);
		animation = ObjectAnimator.ofPropertyValuesHolder(view, pvhY);
		animation.setDuration(300);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animator animation) {
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		animation.start();
	}
}
